import Vue from 'vue'
import VueRouter from 'vue-router'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'

Vue.use(VueRouter)

const routesAll = [];
const routesList = require.context(
	'./routes',
	false,
	/\.js$/
);

routesList.keys().forEach(name => {
	const item = routesList(name).default || routesList(name);
	routesAll.push(item);
});

const routes = [
	{
		path: '/',
		redirect(val) {
			console.log(val)
			return '/home'
		}
	},
  // ...routesAll,
];

const router = new VueRouter({
  routes
});

router.addRoutes(routesAll)
router.options.routes.push(...routesAll);

// 路由导航
NProgress.inc(.2);
NProgress.configure({
	easing: 'ease',
	// speed: 4000,
	showSpinner: false,
	trickle: false,
});
router.beforeEach((to, from, next) => {
	NProgress.start();
	next();
});

router.afterEach((to, from) => {
	NProgress.done();
	// console.log(to, from);
});

export default router;
